#pragma once
//============================================================================
// Copyright (C) 2009-2013 Brett R. Jones 
// All Rights Reserved
//
// You may redistribute and/or modify for non commercial and commercial uses 
// provided this copyright notice remains in place and is not modified
//
// This code is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// brettjones1900@gmail.com
// http://www.p2panarchy.com
//============================================================================


class RcWebPageBuilder : public RcWebServer
{
public:
	//=== constructor ===//
	RcWebPageBuilder();

	//=== methods ===//
	//! shutdown web builder
	RCODE	ShutdownWebPageBuilder( void )
	{
		m_oBuildThread.KillThread();
		return 0;
	}
	//! rebuild web site
	RCODE	BuildWebSite( void );

	//! rebuild web site called from thread
	RCODE	DoBuildWebSite( void );

	//! get build website progress
	virtual int GetBuildProgress( void ){ return m_iBuildProgress; }

	//! called when website is ready
	//! non zero error if error occured
	virtual void webSiteReadyCallback( int iError ){ }

	//! build html indexes of shared files
	RCODE	BuildFileIndex(	std::string strMyFilesTitle,			// title of files
							std::string strMyFilesAlias,			// alias directory ( releative to website root )
							std::string strMyFilesWebDir,			// website directory
							std::string strMyFilesRealDir,			// shared files directory
							std::string strMyFilesParentIdxFile );	// parent index file

	//! make html accepatable name.. replace spaces with %20
	char *	MakeHtmlAcceptableName( const char * pName );

	//! format file length into 6 character string
	void	FormatFileSize( U64 u64FileSize, char * pBuf );


	//=== vars ===//
	BOOL				m_bBuildWebSiteSuccess;		// if true website build completed successfully
	BOOL				m_bBuildWebSiteFail;		// if true website build failed
	RCODE				m_rcLastBuildErr;			// last build error
	int					m_iBuildProgress;			// percent progress of build website

	U64					m_u64TotalSharedBytes;		// number of bytes shared in shared files


	VxThread			m_oBuildThread;		// thread to do website building
	VxMutex				m_oMutex;			// mutex for website access

	
};